package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.purchase.RCServiceProductPurchaseRequest;
import com.shrct.businessprocess.purchase.RCServiceProductPurchaseRequestCriteria;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import org.hibernate.Query;

public class RCServiceProductPurchaseRequestCriteriaImpl extends HQLBasedPagedQueryCriteria<RCServiceProductPurchaseRequest> implements RCServiceProductPurchaseRequestCriteria {
  private RCProject project;
  
  public RCProject getProject() {
    return this.project;
  }
  
  public RCServiceProductPurchaseRequestCriteria setProject(final RCProject project) {
    this.project = project;
    return this;			
    
  }
  
  private RCEmployee salesMan;
  
  public RCEmployee getSalesMan() {
    return this.salesMan;
  }
  
  public RCServiceProductPurchaseRequestCriteria setSalesMan(final RCEmployee salesMan) {
    this.salesMan = salesMan;
    return this;			
    
  }
  
  private RCEmployee businessMan;
  
  public RCEmployee getBusinessMan() {
    return this.businessMan;
  }
  
  public RCServiceProductPurchaseRequestCriteria setBusinessMan(final RCEmployee businessMan) {
    this.businessMan = businessMan;
    return this;			
    
  }
  
  private RCEmployee owner;
  
  public RCEmployee getOwner() {
    return this.owner;
  }
  
  public RCServiceProductPurchaseRequestCriteria setOwner(final RCEmployee owner) {
    this.owner = owner;
    return this;			
    
  }
  
  private Boolean isPassed;
  
  public Boolean getIsPassed() {
    return this.isPassed;
  }
  
  public RCServiceProductPurchaseRequestCriteria setIsPassed(final Boolean isPassed) {
    this.isPassed = isPassed;
    return this;			
    
  }
  
  private Boolean isFinished;
  
  public Boolean getIsFinished() {
    return this.isFinished;
  }
  
  public RCServiceProductPurchaseRequestCriteria setIsFinished(final Boolean isFinished) {
    this.isFinished = isFinished;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.purchase.impl.RCServiceProductPurchaseRequestImpl this  left join  this.budget.cbd.project.salers as salerAssignment ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsPassed()) ){
    	hql += " and ((this.isPassed) = (:isPassed))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsFinished()) ){
    	hql += " and ((this.isFinished) = (:isFinished))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProject()) ){
    	hql += " and ((this.budget.cbd.project) = (:project))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSalesMan()) ){
    	hql += " and ((salerAssignment.employee) = (:salesMan))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBusinessMan()) ){
    	hql += " and ((this.budget.cbd.project.customer.businessMan) = (:businessMan))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner()) && !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner()) ){
    	hql += " and ((((this.budget.cbd.project.customer.businessMan) = (:owner)) or ((salerAssignment.employee) = (:owner))) or ((salerAssignment.employee.directManager) = (:owner)))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProject())){
    	query.setParameter("project",getProject()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getSalesMan())){
    	query.setParameter("salesMan",getSalesMan()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getBusinessMan())){
    	query.setParameter("businessMan",getBusinessMan()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getOwner())){
    	query.setParameter("owner",getOwner()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsPassed())){
    	query.setParameter("isPassed",getIsPassed()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsFinished())){
    	query.setParameter("isFinished",getIsFinished()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return true;
  }
  
  public RCServiceProductPurchaseRequestCriteriaImpl() {
    initOrderBys();
  }
}
